﻿@model SW.Lite.Model.Master.AdminModel
@{
    ViewBag.Title = "Role";
    Layout = "~/Areas/Master/Views/Shared/_Layout.cshtml";
}
@section Header{
    <link href="~/Areas/Master/Common/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" />
    <script type="text/javascript" src="~/Areas/Master/Common/js/ztree/jquery.ztree.core-3.5.min.js"></script>
    <script type="text/javascript" src="~/Areas/Master/Common/js/ztree/jquery.ztree.excheck-3.5.min.js"></script>
    <script type="text/javascript">
    var nodes = @Html.Raw(ViewBag.Roles);
    var adminID = '@Model.Id';
    var objTree = null;
    var setting = {
        view: {
            selectedMulti: false,
            showIcon: false
        },
        check: {
            enable: true,
            autoCheckTrigger: true
        }
    };

    $(function() {
        objTree = $.fn.zTree.init($("#adminRole"), setting, nodes);
    });

    function returnParent() {
        location.href = '@Url.Action("Index")';
        }

        function save() {
            var nodes = objTree.getCheckedNodes();
            var jsonRole = [];
            for (var i = 0; i < nodes.length; i++) {
                var node = nodes[i];
                if (node.RoleID)
                    jsonRole.push(node.RoleID);
            }

            Utils.ajax({
                url: '@Url.Action("SaveRole")',
                data: { 'AdminID': adminID, 'jsonRole': jsonRole.join(',') },
                type: 'POST',
                success: function (d) { if (d.Result) location.reload(); },
                error: function (status) { }
            });
        }
    </script>
}
<div class="panel grid_8">
    <div class="panel-header">
        <span class="i-24 i-user">角色管理 -【@Model.NickName】</span>
    </div>
    <div class="panel-body">
        <div class="panel-toolbar top clearfix">
            <ul>
                <li><a id="btnAdd" class="ic-16 ic-page-save" onclick="save();">保存</a></li>
                <li><a id="btnDelete" class="ic-16 ic-arrow-undo" onclick="returnParent();">返回</a></li>
            </ul>
        </div>
        <div class="pad10">
            <ul id="adminRole" class="ztree"></ul>
        </div>
    </div>
</div>